package com.starwish.starwishblog.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.starwish.starwishblog.entity.Category;
import com.starwish.starwishblog.entity.Tag;
import com.starwish.starwishblog.mapper.CategoryMapper;

import com.starwish.starwishblog.vo.CategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryService {
    @Autowired
    CategoryMapper categoryMapper;


    public PageInfo<CategoryVo> showCategoryByPage(Integer now, Integer size, String name) {
        PageHelper.startPage(now, size);
        List<CategoryVo> categorys  = categoryMapper.selectCateByCons(name);
        return new PageInfo<>(categorys);

    }

    public void removeBykey(Integer id) {
        categoryMapper.deleteById(id);
    }

    public void addCate(Category category) {
        categoryMapper.insert(category);
    }

    public void modifyCate(Category category) {
        categoryMapper.updateByPrimaryKey(category);

    }

    public List<CategoryVo> findAll() {
      return   categoryMapper.selectAll();
    }

    public int hotCateById(Integer id,Integer status) {
        return categoryMapper.hotById(id,status);
    }
}
